package com.spring.learn;


import com.spring.learn.model.SystemEntity;
import org.apache.commons.lang.StringUtils;
import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;
import org.springframework.validation.Validator;

/**
 * Created by baiguantao on 2017/12/12.
 */
public class ValidVO implements Validator {


    @Override
    public boolean supports(Class<?> clazz) {
        return SystemEntity.class.equals(clazz);
    }

    @Override
    public void validate(Object target, Errors errors) {
        ValidationUtils.rejectIfEmpty(errors,"name",null,"姓名不能为空!");
        SystemEntity system = (SystemEntity) target;
        if(StringUtils.isEmpty(system.getName())){
            errors.rejectValue("name",null,"系统名称不能为空!!!!");
        }

    }
}
